using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_GroupEdit : Admin, IRequiresSessionState
{
	protected int GroupID;
	protected string Action;
	protected FormView FormView1;
	protected ObjectDataSource ObjectDataSource1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		try
		{
			this.Action = Fetch.Get("Action");
			this.GroupID = Fetch.GetID("GroupID");
			if (this.Action == "AddGroup")
			{
				this.FormView1.DefaultMode = FormViewMode.Insert;
			}
			if (!base.admin.CheckAdminPower(28))
			{
				base.WriteLog("View", Language.GetAdminMsg("Log/Access", this.GroupID.ToString()), "UserGroup");
				base.WriteRightErrMsg();
			}
		}
		catch
		{
			this.WriteErrMsg("", Language.Get("Common/ParamErr", "Admin"), "");
			base.Response.End();
		}
		if (!base.admin.CheckAdminPower(29))
		{
			this.FormView1.Enabled = false;
		}
	}
	protected void ObjectDataSource1_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
	{
		if (e.ReturnValue != null)
		{
			base.WriteLog("AddNew", Language.GetAdminMsg("Log/ObjectID", e.ReturnValue.ToString()), "UserGroup");
			this.WriteSuccessMsg("", Language.GetAdminMsg("Common/AddSuccess"), "Admin_Group.aspx");
		}
	}
	protected void ObjectDataSource1_Updated(object sender, ObjectDataSourceStatusEventArgs e)
	{
		base.WriteLog("Modify", Language.GetAdminMsg("Log/ObjectID", "0"), "UserGroup");
		this.WriteSuccessMsg("", Language.GetAdminMsg("Common/EditSuccess"), "Admin_Group.aspx");
	}
	protected void OnSubmit(object sender, ObjectDataSourceMethodEventArgs e)
	{
		if (e.InputParameters["GroupName"] == null)
		{
			this.WriteErrMsg("", Language.Get("Common/LostParam", "GroupName"), "");
		}
		if (e.InputParameters["GroupIntro"] == null)
		{
			this.WriteErrMsg("", Language.Get("Common/LostParam", "GroupIntro"), "");
		}
		if (e.InputParameters["GroupIntro"] == null)
		{
			this.WriteErrMsg("", Language.Get("Common/LostParam", "GroupIntro"), "");
		}
		string text = "";
		CheckBoxList checkBoxList = (CheckBoxList)this.FormView1.FindControl("GroupPower");
		RadioButtonList radioButtonList = (RadioButtonList)this.FormView1.FindControl("IsShow");
		RadioButtonList radioButtonList2 = (RadioButtonList)this.FormView1.FindControl("Locked");
		foreach (ListItem listItem in checkBoxList.Items)
		{
			if (listItem.Selected)
			{
				text = text + listItem.Value + ",";
			}
		}
		if (text != "")
		{
			text += ",";
			text = text.Replace(",,", "");
		}
		e.InputParameters["GroupPower"] = text;
		if (radioButtonList.Items[0].Selected)
		{
			e.InputParameters["IsShow"] = 1;
		}
		else
		{
			e.InputParameters["IsShow"] = 0;
		}
		if (radioButtonList2.Items[0].Selected)
		{
			e.InputParameters["Locked"] = 1;
		}
		else
		{
			e.InputParameters["Locked"] = 0;
		}
	}
	protected void FormView1_OnDataBound(object sender, EventArgs e)
	{
		if (this.FormView1.DefaultMode == FormViewMode.Edit)
		{
			try
			{
				CheckBoxList checkBoxList = (CheckBoxList)this.FormView1.FindControl("GroupPower");
				GroupBll groupBll = new GroupBll(this.conn);
				DataTable groupPowerByID = groupBll.GetGroupPowerByID(this.GroupID);
				string groupPower = groupPowerByID.Rows[0]["GroupPower"].ToString();
				foreach (ListItem listItem in checkBoxList.Items)
				{
					listItem.Selected = groupBll.CheckGroupPower(groupPower, listItem.Value);
				}
				RadioButtonList radioButtonList = (RadioButtonList)this.FormView1.FindControl("IsShow");
				RadioButtonList radioButtonList2 = (RadioButtonList)this.FormView1.FindControl("Locked");
				if (groupPowerByID.Rows[0]["IsShow"].ToString() == "1")
				{
					radioButtonList.Items[0].Selected = true;
				}
				else
				{
					radioButtonList.Items[1].Selected = true;
				}
				if (groupPowerByID.Rows[0]["Locked"].ToString() == "1")
				{
					radioButtonList2.Items[0].Selected = true;
				}
				else
				{
					radioButtonList2.Items[1].Selected = true;
				}
			}
			catch
			{
				this.WriteErrMsg("", Language.Get("Common/LostParam", "Action或GroupID"), "");
				base.Response.End();
			}
		}
	}
}
